package com.example.trance.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/7/2 17:15
 * @Description 测试异步线程任务，线程池 链路是否断链
 */
@Slf4j
@Component
public class TranceAsyncTest {

    @Async(value = "asyncServiceExecutor")
    public void aAsyncTaskTest(){
        sleep();
        log.info("##############asyncServiceExecutor");
        sleep();
    }

    @Async(value = "executorService")
    public void bAsyncTaskTest(){
        sleep();
        log.info("##############executorService");
        sleep();
    }

    @Async(value = "asyncServiceExecutor")
    public void cExecutorTaskTest(){
        sleep();
        log.info("##############asyncServiceExecutor");
        sleep();
    }

    @Async(value = "executorService")
    public void dExecutorTaskTest(){
        sleep();
        log.info("##############executorService");
        sleep();
    }


    private void sleep(){
        try {
            log.info(" start sleep");
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" end sleep");
    }
}
